package com.atguigu.serviceedu.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.serviceedu.entity.EduCourse;
import com.atguigu.serviceedu.entity.EduTeacher;
import com.atguigu.serviceedu.service.EduCourseService;
import com.atguigu.serviceedu.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author JY
 * @create 2021-01-31 17:38
 */
@RestController
//@CrossOrigin
@RequestMapping("/serviceedu/teacherfront")
public class TeacherFrontController {
    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    //前台讲师分页
    @GetMapping("page/{page}/{limit}")
    public R page(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> pageParam = new Page<>(page,limit);
        //用map封装分页需要的数据
        Map<String,Object> map = teacherService.pageList(pageParam);

        return R.ok().data(map);
    }

    //前台讲师详情
    @GetMapping("getTeacherInfoById/{id}")
    public R getTeacherInfoById(@PathVariable String id){
        //得到讲师数据
        EduTeacher teacher = teacherService.getById(id);
        //得到相对应的课程数据
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> courseList = courseService.list(wrapper);
        return R.ok().data("teacher", teacher).data("courseList", courseList);
    }
}
